package com.lancoo.znbkxx.teacher.adapter

import android.annotation.SuppressLint
import android.os.Build
import android.text.Html
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.AnswerDetail
import com.lancoo.znbkxx.teacher.utils.HtmlUtils
import kotlinx.android.synthetic.main.item_stuanswer_detail.view.*
import java.math.BigDecimal

/**
 * @author : wealive
 * @date   : 2020/3/23 11:09
 * @desc   :
 */
class AnswerDetailAdapter(
        private val onAudioClickListener: AnswerListAdapter.OnAudioClickListener,
        layoutResId: Int, data: MutableList<AnswerDetail>
) :
        BaseQuickAdapter<AnswerDetail, BaseViewHolder>(layoutResId, data) {
    @SuppressLint("SetTextI18n")
    override fun convert(helper: BaseViewHolder, item: AnswerDetail?) {
        with(helper.itemView) {
            tv_stuName.text = "${item!!.StuName}的作答"
            tv_score.text =
                    HtmlUtils.setText(
                            "<font color='7e7e7e'>得分率:</font><font color='#ff9900'>${BigDecimal(
                                    item.ScoreRate * 100).stripTrailingZeros()}%</font>")
            val adapter = AnswerListAdapter(R.layout.item_stu_answer, item.AnswerList,
                    onAudioClickListener, helper.layoutPosition)
            adapter.onItemClickListener = this@AnswerDetailAdapter.onItemClickListener
            rv.layoutManager = LinearLayoutManager(context)
            rv.adapter = adapter
        }
    }
}